﻿
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.Model;
using Gift.DAL;
using Gift.Utile;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;
namespace WebApp.admin.message
{
    public partial class groupSendMessage : BaseAdmin
    {

        tbOutBox oOutBox = new tbOutBox();
      
        readonly DALUser theUser = new DALUser();

        // Methods
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string pathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
            try
            {
                this.oOutBox.sender = "管理员";
                this.oOutBox.title = this.txtTitle.Value;
                this.oOutBox.content = this.txtaContent.Value;
              
                ArrayList list = ArrayList.Adapter(base.Request.Form["addUser"].Split(new char[] { ',' }));
                foreach (string str2 in list)
                {
                    this.oOutBox.addressee = str2;
                    BaseFactory.theOutBox.SendEmail(this.oOutBox);
                }
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"发送成功！\");location.href=\"messageOutboxList.aspx\";</script>");
            }
            catch
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"发送失败！\");</script>");
            }
        }

        public StringBuilder GetBcakLocation()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                if (base.Request.QueryString["t"] == null)
                {
                    return builder;
                }
                if (base.Request.QueryString["t"] == "ib")
                {
                    builder.Append("location.href='in_box.aspx';");
                    return builder;
                }
                builder.Append("location.href='out_box.aspx';");
            }
            catch
            {
            }
            return builder;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
            //{
            //    base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
            //}
        }

        protected StringBuilder UserBind()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                DataTable allUserEmail = this.theUser.GetAllUserEmail();
                foreach (DataRow row in allUserEmail.Rows)
                {
                    builder.AppendLine("<option value=\"" + row["userName"].ToString() + "\">" + row["userName"].ToString() + "</option>");
                }
            }
            catch
            {
            }
            return builder;
        }

    }
}